package com.kaesar.leetcode.LeetCode_351_400;

public class LeetCode_367 {
    /**
     * 二分查找法
     * @param num
     * @return
     */
    public static boolean isPerfectSquare(int num) {
        int low = 1, high = (int) Math.sqrt(Integer.MAX_VALUE);
        while (low <= high) {
            int mid = (low + high) / 2;
            if (mid * mid == num) {
                return true;
            } else if (mid * mid > num) {
                high = mid - 1;
            } else if (mid * mid < num) {
                low = mid + 1;
            }
        }

        return false;
    }

    public static void main(String[] args) {
        System.out.println(isPerfectSquare(14));
    }
}
